package utility;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.StringTokenizer;

public class DateTool {
private static SimpleDateFormat date_format;
public static int day;
public static int month;
public static int year;
public static void setDateFormat(String format){
	date_format=new SimpleDateFormat(format);
}
/**
 * Input String and return sqlDate with default format;
 * @param date
 * @return
 */
public static java.sql.Date getDateSQL(String date){
	java.util.Date x=new  Date();
	setDateFormat("yyyy/MM/dd");
	try {
		x=date_format.parse(date);
		return new java.sql.Date(x.getTime());
	} catch (ParseException e) {
		e.printStackTrace();
	}
	return null;
}
/**
 * Input String and return sqlDate with specific format;
 * @param date
 * @param format
 * @return
 */
public static java.sql.Date getDateSQL(String date,String format){
	java.util.Date x=new  Date();
	setDateFormat(format);
	try {
		x=date_format.parse(date);
		return new java.sql.Date(x.getTime());
	} catch (ParseException e) {
		e.printStackTrace();
	}
	return null;
}
/**
 * Get string from date
 * @param date
 * @return
 */
public static String getString(java.util.Date date){
	setDateFormat("yyyy/MM/dd");
	return date_format.format(date);
}
/**
 * Get string from date with specific format
 * @param date
 * @param format
 * @return
 */
public static String getString(java.util.Date date,String format){
	setDateFormat(format);
	return date_format.format(date);
}

public static void setValue(String date){
	StringTokenizer cut=new StringTokenizer(date, "/");
	while(cut.hasMoreTokens()){
		year=Integer.parseInt(cut.nextToken());
		month=Integer.parseInt(cut.nextToken());
		day=Integer.parseInt(cut.nextToken());
	}
}
public static void main(String[] args) {
	System.out.println(getString(new java.util.Date(),"dd-MM-yyyy"));
	//System.out.println(new java.util.Date());
	setValue(getString(new java.util.Date()));
	System.out.println(DateTool.day);
	System.out.println(DateTool.month);
	System.out.println(DateTool.year);
	
}

}
